﻿Public Class NhanVienDAO

    Private connect As ConnectDB
    Private sqlstr As String


    Public Sub New()
        connect = New ConnectDB()
    End Sub

    Public Function IsUpNV(ByVal emp As NhanVienDTO, ByVal flag As Boolean)
        Dim IDNV As String = emp.Tên_đăng_nhập
        Dim Pass As String = emp.Mật_khẩu
        Dim Hoten As String = emp.Họ_tên
        Dim Ngaysinh As String = emp.Ngày_sinh
        Dim Gioitinh As String = emp.Giới_tính
        Dim Diachi As String = emp.Địa_chỉ
        Dim Sodt As String = emp.Điện_thoại
        Dim LoaiNV As String = emp.Mã_loại_NV

        If flag = True Then
            sqlstr = "INSERT NHANVIEN(IDNV, PassVN, HoTen, NgaySinh, GioiTinh, DiaChi, SoDienThoai, IDLoaiNV)" & _
                "VALUES('" & IDNV & "', '" & Pass & "', '" & Hoten & "', '" & Ngaysinh & "', '" & _
                Gioitinh & "', '" & Diachi & "', '" & Sodt & "', '" & LoaiNV & "')"

        Else
            sqlstr = "UPDATE NHANVIEN SET PassVN  = '" & Pass & _
                                        "', HoTen   = '" & Hoten & _
                                        "', NgaySinh      = '" & Ngaysinh & _
                                        "',  GioiTinh      = '" & Gioitinh & _
                                        "', DiaChi   = '" & Diachi & _
                                        "', SoDienThoai      = '" & Sodt & _
                                        "',  IDLoaiNV      = '" & LoaiNV & _
                                    "' WHERE IDNV  = '" & IDNV & "'"
        End If
        Return connect.Execute(sqlstr)
    End Function

    Public Function DeleteNV(ByVal emp As NhanVienDTO)
        Dim idNV As String = emp.Tên_đăng_nhập
        sqlstr = "DELETE NHANVIEN WHERE IDNV = '" & idNV & "'"
        Return connect.Execute(sqlstr)
    End Function

    Public Function Getdata() As List(Of NhanVienDTO)
        Dim i As Integer
        Dim id, pw, ht, ns, gt, dc, sdt, lnv As String
        Dim emp As NhanVienDTO
        Dim empLst As New List(Of NhanVienDTO)
        Dim dt As New DataTable
        dt = connect.GetData("Select * From NHANVIEN")

        For i = 0 To dt.Rows.Count() - 1
            id = dt.Rows(i)("IDNV").ToString
            pw = dt.Rows(i)("PassVN").ToString
            ht = dt.Rows(i)("HoTen").ToString
            ns = dt.Rows(i)("NgaySinh").ToString
            gt = dt.Rows(i)("GioiTinh").ToString
            dc = dt.Rows(i)("DiaChi").ToString
            sdt = dt.Rows(i)("SoDienThoai").ToString
            lnv = dt.Rows(i)("IDLoaiNV").ToString
            emp = New NhanVienDTO(id, pw, ht, ns, gt, dc, sdt, lnv)
            empLst.Add(emp)
        Next
        Return empLst
    End Function

    


End Class
